using Net35.Xrm.Sdk.Query;
using System;
namespace Net35.Xrm.Sdk.Linq
{
	internal static class FilterExpressionExtensions
	{
		public delegate void FilterAction(FilterExpression exp, FilterExpression parent);
		public delegate void ConditionAction(ConditionExpression exp, FilterExpression parent);
		public static void ForSubtreePreorder(this FilterExpression exp, FilterExpressionExtensions.FilterAction action)
		{
			exp.ForSubtreePreorder(null, action);
		}
		public static void ForSubtreePreorder(this FilterExpression exp, FilterExpression parent, FilterExpressionExtensions.FilterAction action)
		{
			action(exp, parent);
			if (exp.Filters != null)
			{
				foreach (FilterExpression current in exp.Filters)
				{
					current.ForSubtreePreorder(exp, action);
				}
			}
		}
		public static void ForSubtreePreorder(this FilterExpression exp, FilterExpressionExtensions.FilterAction filterAction, FilterExpressionExtensions.ConditionAction conditionAction)
		{
			exp.ForSubtreePreorder(null, filterAction, conditionAction);
		}
		public static void ForSubtreePreorder(this FilterExpression exp, FilterExpression parent, FilterExpressionExtensions.FilterAction filterAction, FilterExpressionExtensions.ConditionAction conditionAction)
		{
			exp.ForSubtreePreorder(parent, delegate(FilterExpression e, FilterExpression p)
			{
				filterAction(e, p);
				if (e.Conditions != null)
				{
					foreach (ConditionExpression current in e.Conditions)
					{
						conditionAction(current, e);
					}
				}
			});
		}
		public static void ForSubtreePostorder(this FilterExpression exp, FilterExpressionExtensions.FilterAction action)
		{
			exp.ForSubtreePostorder(null, action);
		}
		public static void ForSubtreePostorder(this FilterExpression exp, FilterExpression parent, FilterExpressionExtensions.FilterAction action)
		{
			if (exp.Filters != null)
			{
				foreach (FilterExpression current in exp.Filters)
				{
					current.ForSubtreePostorder(exp, action);
				}
			}
			action(exp, parent);
		}
		public static void ForSubtreePostorder(this FilterExpression exp, FilterExpressionExtensions.FilterAction filterAction, FilterExpressionExtensions.ConditionAction conditionAction)
		{
			exp.ForSubtreePostorder(null, filterAction, conditionAction);
		}
		public static void ForSubtreePostorder(this FilterExpression exp, FilterExpression parent, FilterExpressionExtensions.FilterAction filterAction, FilterExpressionExtensions.ConditionAction conditionAction)
		{
			exp.ForSubtreePostorder(parent, delegate(FilterExpression e, FilterExpression p)
			{
				if (e.Conditions != null)
				{
					foreach (ConditionExpression current in e.Conditions)
					{
						conditionAction(current, e);
					}
				}
				filterAction(e, p);
			});
		}
	}
}
